package com.jsmtr.rms.controller.UserResumeView;

import com.jsmtr.rms.service.IDoResumeService;
import com.jsmtr.rms.utils.ResultBean;
import com.jsmtr.rms.utils.StringTools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 应聘者应聘历史控制
 * @author: cyx
 * @description:
 * @date: Created in 2019/2/15 11:52
 * @modified by:
 */
@Controller
public class UserResumeHistoryController {

    @Resource
    private IDoResumeService doResumeService;

    @ResponseBody
    @RequestMapping(value = "/UserResume/RecruitmentHistory")
    public ResultBean RecruitmentHistory(HttpServletRequest request, HttpServletResponse response){
        String cardNo=request.getParameter("cardno");
        ResultBean resultBean=new ResultBean();
        try {
            List<Map<String,Object>> userResumeList= doResumeService.getDResumeByCardNo(cardNo);
            if(userResumeList!=null&&userResumeList.size()>0){
                List<Map> resultList=new ArrayList<>();
                for (Map<String,Object> dUserResume : userResumeList) {
                    Map resultMap=new HashMap<String,String>();
                    resultMap.put("id",dUserResume.get("ID"));
                    resultMap.put("cardno",dUserResume.get("CARDNO"));
                    resultMap.put("name",dUserResume.get("NAME"));
                    resultMap.put("sexname",dUserResume.get("SEXNAME"));
                    resultMap.put("proid",dUserResume.get("PROID"));
                    resultMap.put("proname",dUserResume.get("PRONAME"));
                    resultMap.put("adddate", dUserResume.get("JTIME"));
                    resultMap.put("jname", dUserResume.get("JNAME"));
                    resultMap.put("fid",dUserResume.get("FID"));
                    if(dUserResume.get("LASTFLOW")!=null&&dUserResume.get("LASTFLOW").toString().equalsIgnoreCase("背景调查")){
                        resultMap.put("lastflow","面试");
                    }else{
                        resultMap.put("lastflow",dUserResume.get("LASTFLOW"));
                    }

                    resultMap.put("fqdate",dUserResume.get("FQTIME"));
                    if(dUserResume.get("FQFLOW")!=null&&dUserResume.get("FQFLOW").toString().equalsIgnoreCase("背景调查")){
                        resultMap.put("fqflow","面试");
                    }else{
                        resultMap.put("fqflow",dUserResume.get("FQFLOW"));
                    }

                    resultMap.put("rfid",dUserResume.get("RFID"));
                    resultMap.put("fqstate",dUserResume.get("FQSTATE"));
                    if (dUserResume.get("RFID")!=null){
                        Object rfid=dUserResume.get("RFID");
                        Object njname=dUserResume.get("NJNAME");
                        Object fqstate=dUserResume.get("FQSTATE");
                        if(fqstate.toString().equalsIgnoreCase("未放弃")){
                            if(StringTools.trimNotEmpty(njname)){
                                resultMap.put("fqstate","已转岗("+njname+")");
                            }
                        }
                    }
                    resultList.add(resultMap);
                }
                resultBean.setTotalResult(String.valueOf(userResumeList.size()));
                resultBean.setState(true);
                resultBean.setMessage("操作成功!");
                resultBean.setDatas(resultList);
            }else{
                resultBean.setState(false);
                resultBean.setMessage("该人员尚未参加应聘!");
                resultBean.setDatas(userResumeList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return  resultBean;
        }
        return resultBean;
    }

}
